package file;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2022-10-29
 * Time: 19:04
 */

//字节流读文件
//读也分情况 一次读一个这字节 和 一次读若干个字节
public class Demo1 {
    //一次读若干个字节
    public static void main(String[] args) {
        try {
            InputStream inputStream = new FileInputStream("e:/kk.txt");
            //准备一个空的字符数组来接收
            while (true){
                byte[] kk = new byte[1024];
                int b = inputStream.read(kk);
                if (b == -1){
                    break;
                }
                for (int i = 0; i < b; i++) {
                    System.out.println(kk[i]);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    //读也分情况 一次读一个这字节
    public static void main1(String[] args) throws IOException {
        InputStream inputStream = new FileInputStream("e:/kk.txt");
        while (true){
            int b = inputStream.read();
            if (b == -1){
                break;
            }
            System.out.println(b);
        }
    }
}
